package com.starbaba.mall.service.impl;

import com.base.common.exception.AppException;
import com.base.common.log.LogService;
import com.starbaba.base.dao.LoanManagerBaseDao;
import com.starbaba.mall.service.LoanMallUserTaobaoOrderService;
import com.tuanzi.server.loan_base.constant.MallTaobaoOrderStatus;
import com.tuanzi.server.loan_base.constant.mall.MallTaobaoOrderResult;
import com.tuanzi.server.loan_base.constant.mall.MallTaobaoOrderType;
import com.tuanzi.server.loan_base.model.db.Loan_Mall_User_Taobao_Order;
import com.tuanzi.server.loan_base.util.DateUtils;

public class LoanMallUserTaobaoOrderServiceImpl extends LoanManagerBaseDao implements LoanMallUserTaobaoOrderService{

	@Override
	public Loan_Mall_User_Taobao_Order getLoanMallUserTaobaoOrder(String orderid) {
		
		String sql = "select * from `loan_mall_user_taobao_order` where orderid = ? ";
		Loan_Mall_User_Taobao_Order order = null;
		try {
			
			order = getDao().get(sql, Loan_Mall_User_Taobao_Order.class, orderid);
			
		} catch (AppException e) {
			LogService.error(e);
		}
		
		return order;
	}

	@Override
	public int updateLoanMallUserTaobaoOrder(String orderid) {
		
		String sql = "UPDATE `loan_mall_user_taobao_order` SET `status` = ?, `result` = ? WHERE `orderid` = ? AND `status` = ?";
		int result = 0;
		try {
			
			result = getDao().update(sql, MallTaobaoOrderStatus.IMPORT, MallTaobaoOrderResult.CHECK_SUCCESS, orderid, MallTaobaoOrderStatus.NOT_IMPORT);
			
		} catch (AppException e) {
			LogService.error(e);
		}
		
		return result;
	}

	@Override
	public int updateLoanMallUserTaoBaoOrder() {
		String sql = "UPDATE `loan_mall_user_taobao_order` SET `result` = ? WHERE `status` = ? AND `type` = ? AND `createtime` < ?";
		int result = 0;
		try {
			
			result = getDao().update(sql, MallTaobaoOrderResult.CHECK_FAIL, MallTaobaoOrderStatus.NOT_IMPORT,
					MallTaobaoOrderType.USER_UPLOAD, DateUtils.getCurrentTime());
			
		} catch (AppException e) {
			LogService.error(e);
		}
		return result;
	}

}
